<template>
  <keep-alive>
    <iframe :src="url" frameborder="0" id="bdIframe" ref="iframe" scrolling="yes"></iframe>
  </keep-alive>
</template>

<script>
export default {
  name: 'iframe1',
  data() {
    return {
      url: '',
      title: ''
    }
  },
  created() {},
  mounted() {
    this.title = this.$route.meta.title
    let srcData = this.$store.state.iframeSrc
    this.url = this.$route.params.url
    if (srcData.length > 0) {
      let flag = srcData.some(item => {
        return item.title === this.title
      })
      if (flag) {
        srcData.forEach(item => {
          if (item.title === this.title) {
            const oIframe = document.getElementById('bdIframe')
            oIframe.style.width = 100 + '%'
            oIframe.style.height = 99 + '%'
          }
        })
      } else {
        const oIframe = document.getElementById('bdIframe')
        oIframe.style.width = 100 + '%'
        oIframe.style.height = 99 + '%'
      }
    } else {
      const oIframe = document.getElementById('bdIframe')
      oIframe.style.width = 100 + '%'
      oIframe.style.height = 99 + '%'
    }

    // iframe
  },
  beforeDestroy() {
    if (this.title != '') {
      this.$store.commit('setIframeSrc', { title: this.title, src: this.url })
    }
  }
}
</script>

<style scoped>
</style>
